package com.vcredit.creditcat.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.enumtype.EMStatusEnum;
import com.vcredit.creditcat.model.AuthSecredit;
import com.vcredit.creditcat.persistence.base.AuthSecreditMapper;

/**
 * 
 **/
@Service
public class AuthSecreditService {
	@Autowired
	private AuthSecreditMapper mapper;

	public void insert(AuthSecredit obj) {
		mapper.insert(obj);
	}

	public void update(AuthSecredit obj) {
		mapper.update(obj);
	}

	public List<AuthSecredit> findAll() {
		return mapper.findAll();
	}

	public List<AuthSecredit> find(AuthSecredit obj) {
		return mapper.find(obj);
	}

	public AuthSecredit findByProcessId(Long processId) {
		if(null == processId) {
			return null;
		}
		AuthSecredit param = new AuthSecredit();
		param.setProcessId(processId);
		List<AuthSecredit> list = find(param);
		if (list.isEmpty()) {
			param.setAuthStatus(EMStatusEnum.INIT.getCode());
			param.setExpiredTime("");
			insert(param);
			return param;
		} else {
			return list.get(0);
		}
	}

	public void resetStatus(AuthSecredit param) {
		update(param);
	}
}